Skip to content

fix(scanner): treat colon as plain scalar content in flow mapping keys#866

Closed
lawrence3699 wants to merge 1 commit intogoccy:masterfrom
lawrence3699:fix/flow-map-colon-in-plain-key
Closed

fix(scanner): treat colon as plain scalar content in flow mapping keys#866
lawrence3699 wants to merge 1 commit intogoccy:masterfrom
lawrence3699:fix/flow-map-colon-in-plain-key

Conversation

@lawrence3699
Copy link
Copy Markdown

Fixes #832

Problem: Parsing {hello:world: [a,b,c]} fails with ',' or '}' must be specified, but this is valid YAML. The unquoted key hello:world is valid because the first : is not followed by whitespace. Without curly braces, parsing succeeds.

Cause: In scanMapDelim(), when inside a flow mapping (startedFlowMapNum > 0), almost every : was treated as a mapping value indicator. The only exception was : followed by / (for URLs). This meant hello:world was split at the first :.

Fix: In flow mapping context, when scanning a plain scalar key (buffer is non-empty), : is only treated as a mapping value indicator when followed by:

  • Whitespace (space, tab, newline)
  • A flow indicator (,, }, ])
  • A flow collection start ([, {)
  • A quote (", ')
  • End of input

When the buffer is empty (key was already tokenized, e.g. as a quoted string), : remains a delimiter unconditionally. This subsumes the previous :/ special case for URLs.

Before: {hello:world: [a,b,c]} → error
After: {hello:world: [a,b,c]}map[hello:world:[a b c]]

Validation: All existing tests pass, including the yaml-test-suite (355/402 = 88.3%, unchanged). Five regression tests added covering single and multiple colons in keys, mixed entries, and nested flow collections.

In flow mapping context, a ':' not followed by whitespace, a flow
indicator, or a quote should be part of the plain scalar key, not a
mapping value indicator. This fixes parsing of inputs like
{hello:world: [a,b,c]} where the key is the plain scalar 'hello:world'.

Fixes goccy#832
Copilot AI review requested due to automatic review settings April 12, 2026 15:28
@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.66%. Comparing base (edee2f9) to head (1a577c7).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #866   +/-   ##
=======================================
  Coverage   80.65%   80.66%           
=======================================
  Files          22       22           
  Lines        6845     6848    +3     
=======================================
+ Hits         5521     5524    +3     
  Misses        905      905           
  Partials      419      419           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes flow-mapping key scanning so that : can be treated as plain-scalar content in unquoted keys when it is not followed by a “value-indicating” character sequence, resolving parsing failures like {hello:world: [a,b,c]} (Issue #832).

Changes:

  • Updated Scanner.scanMapDelim() to only treat : as a mapping value indicator in flow mappings when the next character makes the delimiter unambiguous (whitespace, flow indicators, collection starts, quotes, or EOS) and the current plain-scalar buffer is non-empty.
  • Added regression tests covering single/multiple colons in keys and nested flow structures.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
scanner/scanner.go Refines : delimiter detection in flow mappings to allow unquoted keys like hello:world while keeping : a delimiter when unambiguous.
decode_test.go Adds regression coverage for colon-containing unquoted keys in flow mappings, including nested flow collections.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Yaml wrapped in curly braces with inline array fails to parse

3 participants